//
//  CommentView.swift
//  EyeVisionForPatients
//
//  Created by qdsg on 2020/4/13.
//  Copyright © 2020 QDSG. All rights reserved.
//

import UIKit

class CommentView: UIView, StarRatingViewDelegate {
    
    var delegate: StarRatingViewDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        setUI()
    }

    func setUI() {
        self.alpha = 0
        mainWindow?.addSubview(self)
    }
    
    func show() {
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 1
        }) { (finish) in
            
        }
    }
    
    func dismiss() {
        UIView.animate(withDuration: 0.3, animations: {
            self.alpha = 0
        }) { (finish) in
            if finish {
                self.removeFromSuperview()
            }
        }
    }
    
    @IBAction func closeBtnAction(_ sender: Any) {
        dismiss()
    }
    
    @IBOutlet weak var starRatingView: StarRatingView! {
        didSet {
            starRatingView.clickEnable = true
            starRatingView.wholeStar = true
            starRatingView.delegate = self
        }
    }
    
    @IBOutlet weak var bgView: UIView! {
        didSet {
            let corner: UIRectCorner = [.topLeft, .topRight]
            bgView.setLayerCorners(rect: bgView.frame, radius: 26, corners: corner)
        }
    }
    
    func starRatingView(_ starRatingView: StarRatingView, count: Float) {
        delegate?.starRatingView?(starRatingView, count: count)
        dismiss()
    }
    
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
